package com.itcjb.springboot.controller;

import com.itcjb.springboot.entity.Authority;
import com.itcjb.springboot.entity.JsonResult;
import com.itcjb.springboot.entity.Role;
import com.itcjb.springboot.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** @author chenjiebin */
@RestController
@RequestMapping("/json")
public class JsonController {

    @GetMapping("/user")
    public User getUser() {
        return new User("000", "admin1", "admin1");
    }

    @GetMapping("/list")
    public List<User> getUserList() {
        List<User> list = new ArrayList<>();
        list.add(new User("001", "admin2", "admin2"));
        list.add(new User("002", "root", "root"));
        list.add(new User("003", "manager", "manager"));
        return list;
    }

    @GetMapping("/map")
    public Map<String, Object> getUserMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("用户信息", new User("004", "ysxt", "ysxt"));
        map.put("百度网址", "https://www.baidu.com/");
        map.put("git地址", "https://www.gitee.com/");
        map.put("电话", null);
        return map;
    }

    @GetMapping("/role")
    public Role getRole() {
        Role role = new Role();
        role.setId("001");
        role.setRolename("管理员");
        List<Authority> list = new ArrayList<>();
        list.add(new Authority("a01", "查询"));
        list.add(new Authority("a02", "更新"));
        list.add(new Authority(null, "删除"));
        role.setAuthorities(list);
        return role;
    }

    @GetMapping("/user2")
    public JsonResult<User> getUser2() {
        return new JsonResult<>(new User("000", "jsonResult", "jsonResult"));
    }

    @GetMapping("/list2")
    public JsonResult<List<User>> getUserList2() {
        List<User> list = new ArrayList<>();
        list.add(new User("001", "test2", "test2"));
        list.add(new User("002", "root", "root"));
        list.add(new User("003", "manage", "manage"));
        return new JsonResult<>(list);
    }

}
